package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：预警管理键值转换
 * @Date：Create by 2023-12-15 11:20:26
 */
public interface IEarlyWarningRecordFilter {

	String WARNING_TYPE = "warningType" ;
	String METER_CONDITION = "meterCondition" ;
	String PUSH_RULE = "pushRule" ;
	String JUDGE_RULE = "judgeRule" ;
	String THRESHOLD_LEVEL = "thresholdLevel" ;
	String STATUS = "status" ;

	String EARLY_WARNING_RECORD_WARNING_TYPE = "ecp-admin.earlyWarningRecord.warningType" ;
	String EARLY_WARNING_RECORD_METER_CONDITION = "ecp-admin.earlyWarningRecord.meterCondition" ;
	String EARLY_WARNING_RECORD_PUSH_RULE = "ecp-admin.earlyWarningRecord.pushRule" ;
	String EARLY_WARNING_RECORD_JUDGE_RULE = "ecp-admin.earlyWarningRecord.judgeRule" ;
	String EARLY_WARNING_RECORD_THRESHOLD_LEVEL = "ecp-admin.earlyWarningRecord.thresholdLevel" ;
	String EARLY_WARNING_RECORD_STATUS = "ecp-admin.earlyWarningRecord.status" ;

	class EarlyWarningRecordExportFilter implements ValueFilter {

		private Map<String, String> warningTypeMap;
		private Map<String, String> meterConditionMap;
		private Map<String, String> pushRuleMap;
		private Map<String, String> judgeRuleMap;
		private Map<String, String> thresholdLevelMap;
		private Map<String, String> statusMap;

		public EarlyWarningRecordExportFilter() {
			warningTypeMap = DictHelper.i().stringVlMap(EARLY_WARNING_RECORD_WARNING_TYPE);
			meterConditionMap = DictHelper.i().stringVlMap(EARLY_WARNING_RECORD_METER_CONDITION);
			pushRuleMap = DictHelper.i().stringVlMap(EARLY_WARNING_RECORD_PUSH_RULE);
			judgeRuleMap = DictHelper.i().stringVlMap(EARLY_WARNING_RECORD_JUDGE_RULE);
			thresholdLevelMap = DictHelper.i().stringVlMap(EARLY_WARNING_RECORD_THRESHOLD_LEVEL);
			statusMap = DictHelper.i().stringVlMap(EARLY_WARNING_RECORD_STATUS);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, WARNING_TYPE)) {
				return CommonUtils.orElse(warningTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, METER_CONDITION)) {
				return CommonUtils.orElse(meterConditionMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, PUSH_RULE)) {
				return CommonUtils.orElse(pushRuleMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, JUDGE_RULE)) {
				return CommonUtils.orElse(judgeRuleMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, THRESHOLD_LEVEL)) {
				return CommonUtils.orElse(thresholdLevelMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

	class EarlyWarningRecordUploadFilter implements ValueFilter {

		private Map<String, String> warningTypeMap;
		private Map<String, String> meterConditionMap;
		private Map<String, String> pushRuleMap;
		private Map<String, String> judgeRuleMap;
		private Map<String, String> thresholdLevelMap;
		private Map<String, String> statusMap;

		public EarlyWarningRecordUploadFilter() {
			warningTypeMap = DictHelper.i().stringLvMap(EARLY_WARNING_RECORD_WARNING_TYPE);
			meterConditionMap = DictHelper.i().stringLvMap(EARLY_WARNING_RECORD_METER_CONDITION);
			pushRuleMap = DictHelper.i().stringLvMap(EARLY_WARNING_RECORD_PUSH_RULE);
			judgeRuleMap = DictHelper.i().stringLvMap(EARLY_WARNING_RECORD_JUDGE_RULE);
			thresholdLevelMap = DictHelper.i().stringLvMap(EARLY_WARNING_RECORD_THRESHOLD_LEVEL);
			statusMap = DictHelper.i().stringLvMap(EARLY_WARNING_RECORD_STATUS);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, WARNING_TYPE)) {
				return CommonUtils.orElse(warningTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, METER_CONDITION)) {
				return CommonUtils.orElse(meterConditionMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, PUSH_RULE)) {
				return CommonUtils.orElse(pushRuleMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, JUDGE_RULE)) {
				return CommonUtils.orElse(judgeRuleMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, THRESHOLD_LEVEL)) {
				return CommonUtils.orElse(thresholdLevelMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}